unit Init;

{$mode objfpc}{$H+}

//========================================================================================
//
// Unit : Init.pas
//
// Description :
//
// Called By :
//
// Calls : ApplicationDataModule : dmApplication.OpenAppDatabase;
//         ApplicationSettings : ReadASLSettingsFile
//                               ASLSetupFileExists
//                               ReadASLSetupFile
//                               SetApplicationName
//                               SetApplicationVersion
//                               SetApplicationPath
//         ASLDatamodule : dmASLData.ConnectASLDB
//         HUSplashAbout : dlgSplashAbout.ShowSplash
//         Main : FormShow
//
// Ver. : 1.0.0
//
// Date : 7 Nov 2016
//
//========================================================================================

interface

uses
  Classes, Dialogs, Forms, SysUtils,
  // Application units
  ApplicationSettings, ASLDataModule, HUSplashAbout;

function Initialize : boolean;

implementation

uses
  Main;

//========================================================================================
//          PROPERTY ROUTINES
//========================================================================================

//========================================================================================
//          SUPPORT ROUTINES
//========================================================================================

//========================================================================================
//          FUNCTIONAL ROUTINES
//========================================================================================
function Initialize : boolean;

var
  vstrTStr : string;

begin

  frmSettings.ApplicationName := Main.cstrApplicationName;
  frmSettings.ApplicationVersion := Main.cstrApplicationVersion;
  frmSettings.ApplicationDate := Main.cstrApplicationDate;

  dlgSplashAbout.ShowSplash;

  // First we get the Appication path
  GetDir(0, vstrTStr);
  frmSettings.ApplicationPath := vstrTStr;

  // If the Application settings.ini file does not exists then this is an initial
  // installation so we read the Inno Setup ASLSetup.ini file that contains the initial
  // default Data and Tanks paths. After the initial setup, the initial data is then
  // maintained and loaded by the ASL.exe application from the Settings.ini and will
  // track any changes in the Data and Tanks directories made by the user.

  // If the ASL Setup file does not exist we have a major problem and cannot continue
  if not frmSettings.ASLSetupFileExists then
  begin
    showmessage('Unrecoverable error - ASLSetup file not found');
    Result := False;
    Exit;
  end;// if not frmSettings.ASLSetupFileExists

  // If the ASL.ini file does not exist then this is an Initial installation and we have
  // to create the Defaul ASL Data and Tank directories.
 if not frmSettings.ASLSettingsFileExists then
    frmSettings.ReadASLSetupFile;

  // Now we read the ASL.ini Setngs file
  frmSettings.ReadASLSettingsFile;

  // Connect to the Application Database
  if  not dmASLData.ConnectASLDB then
  begin
    showmessage('Application Terminating');
    Result := False;
    Exit;
  end;


  // Now we load the last used Tank file if coonfigured to do so
  // ******** Add code here



  // We have had a successful Initialization
  Result := True;

 end;// function Initialize : boolean

//========================================================================================
//          MENU ROUTINES
//========================================================================================

//========================================================================================
//          TOOLBAR ROUTINES
//========================================================================================

//========================================================================================
//           STATUSBAR ROUTINES
//========================================================================================

//========================================================================================
//          FILE ROUTINES
//========================================================================================

//========================================================================================
//          DATABASE ROUTINES
//========================================================================================

//========================================================================================
//          COMMAND BUTTON ROUTINES
//========================================================================================

//========================================================================================
//          CONTROL ROUTINES
//========================================================================================

//=========================
//  OnChange Routines
//=========================

//=========================
//  OnClick Routines
//=========================

//=========================
//  OnKeypress Routines
//=========================

//========================================================================================
//          FORM ROUTINES
//========================================================================================

//========================================================================================
end.// unit Init;

